<template>
  <div>
    <el-button size="small" type="primary" @click="goback"
      >返回全局赏列表</el-button
    >
    <el-button size="small" type="primary" @click="addGoods"
      >添加赏品</el-button
    >
    <el-table
      ref="multipleTable"
      border
      :data="quanjuGoods"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="ID" prop="id" width="40"> </el-table-column>
      <el-table-column label="赏品名称" prop="name" width="120">
        <template slot-scope="scope">{{ scope.row.good_name }}</template>
      </el-table-column>
      <el-table-column prop="good_title" label="赏品类型" width="120">
        <template v-slot="scope">
          <el-button type="primary" size="mini" round>{{
            scope.row.good_title
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="显示价格" prop="name" width="120">
        <template slot-scope="scope">{{ format_money(scope.row.price) }}</template>
      </el-table-column>
      <el-table-column label="回收价格" prop="name" width="120">
        <template slot-scope="scope">{{
          format_money(scope.row.recovery_price)
        }}</template>
      </el-table-column>
      <el-table-column prop="title" label="赏品图片" width="120">
        <template v-slot="scope">
          <div class="display_url">
            <img :src="scope.row.good_url" />
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="good_desc"
        label="赏品描述"
        width="170"
      ></el-table-column>
      <el-table-column label="操作" width="120">
        <template v-slot="scope">
          <a class="editGood" @click="edit(scope.row)">编辑</a>
          <a class="delGood" @click="del(scope.row.good_uuid)">删除</a>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { StatusCodes } from "http-status-codes";
import quanju from "../../../../api/jurisdiction";
import {format_money} from "@/utils/format";
export default {
  data() {
    return {
      game_uuid: "",
      quanjuGoods: [],
    };
  },
  created() {},
  mounted() {
    this.game_uuid = this.$route.params.id;
    this.getQuanJuGoods();
  },
  methods: {
    format_money,
    goback() {
      this.$router.push("/layout/choushangguanli/quanjushang");
    },
    addGoods() {
      this.$router.push({
        name: "addquanjushangshangpin",
        params: { id: this.game_uuid },
      });
    },
    getQuanJuGoods() {
      quanju
        .getquanjugamegoods({ params: { game_uuid: this.$route.params.id } })
        .then((res) => {
          this.quanjuGoods = res.data.data;
          console.log(res.data);
        })
        .catch((err) => {
          if (err.data.code === -1) {
            this.$router.push("/layout/choushangguanli/quanjushang");
            this.$message.warning("请重新获取赏品列表");
          }
        });
    },
    handleSelectionChange() {},
    edit(id) {
      let data = JSON.stringify(id);
      this.$router.push({
        name: "addquanjushangshangpin",
        query: {
          data,
        },
        params: { id: this.game_uuid },
      });
    },
    //删除赏品
    del(id) {
      this.$confirm("请确认是否删除赏品", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          quanju
            .delquanjugoods({
              data: { game_uuid: this.game_uuid, good_uuid: id },
            })
            .then((res) => {
              console.log(res);
              if (res.data.code == 0) {
                this.$message({ type: "success", message: res.data.msg });
                this.getQuanJuGoods();
              }
            })
            .catch((err) => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消" });
        });
    },
  },
};
</script>

<style lang="less" scoped>
.display_url,
.display_url img {
  width: 60px;
}
.el-table {
  margin-top: 10px;
}
a {
  display: inline-block;
  margin-right: 5px;
  padding: 1px 7px;
  height: 23px;
  border-radius: 23px;
  font-size: 12px;
  background: #009688;
  color: white;
  cursor: pointer;
}
.delGood {
  background: #ff5722;
}
</style>
